package com.power.controller;

import com.alibaba.fastjson.JSON;
import com.power.common.Contants;
import com.power.ov.ResultData;
import com.power.pojo.Inspetion;
import com.power.service.impl.InspeServiceimpl;
import com.power.service.inspeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * User: 李辽
 * Date: 2020/10/10 20:14
 * Description:
 * Version: V1.0
 */
@WebServlet("/EditInspetion.do")
public class EditInspetion extends HttpServlet{
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BufferedReader br = request.getReader();
        String s = br.readLine();
        Inspetion inspetion = JSON.parseObject(s, Inspetion.class);
        System.out.println("进入编辑后台，线路id"+inspetion.getLine_id()+" 线路名称"+inspetion.getLine_name());
        System.out.println("进入编辑后台，巡检编号"+inspetion.getInspection_accont());
        inspeService inspeService = new InspeServiceimpl();
        ResultData resultData = new ResultData();
        try {
            int result = inspeService.EditInspetion(inspetion);
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("编辑成功！！");
            resultData.setData(result);
        } catch (SQLException e) {
            e.printStackTrace();
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("编辑失败！！");
        }
        System.out.println("进入编辑后台执行后的结果："+resultData.toString());
        response.getWriter().write(JSON.toJSONString(resultData));
        response.getWriter().flush();
        response.getWriter().close();
    }
}
